//
//  ZHNavView.m
//  VehicleInsuranceSupport
//
//  Created by TangBin on 2019/11/20.
//  Copyright © 2019 TangBin. All rights reserved.
//

#import "ZHNavView.h"

@interface ZHNavView ()
@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIButton *btnBack;

- (void)initWithTitleLabel;

@end

@implementation ZHNavView

- (void)initWithSubView
{
    self.backgroundColor = kNavBarBackgroundColor;
    
    [self initWithTitleLabel];
    
    [self initWithBtnBack];
}

- (void)initWithTitleLabel
{
    CGRect frame = CGRectMake(60, IPHONEX_TOP_SPACE + SYS_STATUSBAR_HEIGHT, self.width - 120, self.height - IPHONEX_TOP_SPACE - SYS_STATUSBAR_HEIGHT);
    _titleLabel = [UILabel createWithLabel:self frame:frame font:kNavBarTitleFont propertiesBlock:^(UILabel * _Nonnull label) {
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
    }];
//    _titleLabel.backgroundColor = [UIColor redColor];
}

- (void)initWithBtnBack
{
    UIImage *image = kNavBtnBackImage;
    CGRect frame = CGRectMake(10, 0, 28, 28);
    _btnBack = [UIButton createWithButton:self frame:frame font:FONTSIZE(16) action:nil propertiesBlock:^(UIButton * _Nonnull button) {
        [button setImage:image forState:UIControlStateNormal];
    }];
    _btnBack.hidden = YES;
    _btnBack.centerY = _titleLabel.centerY;
}

- (void)setFont:(UIFont *)font
{
    _titleLabel.font = font;
}

- (UIFont *)font
{
    return _titleLabel.font;
}

- (void)setTextColor:(UIColor *)textColor
{
    _titleLabel.textColor = textColor;
}

- (void)setTitle:(NSString *)title
{
    _titleLabel.text = title;
}

- (NSString *)title
{
    return _titleLabel.text;
}

- (void)setIsHiddenBack:(BOOL)isHiddenBack
{
    _isHiddenBack = isHiddenBack;
    _btnBack.hidden = isHiddenBack;
}

/// 添加返回按钮事件
/// @param target target description
/// @param action action description
- (void)addBackTarget:(id)target action:(SEL)action
{
    [self.btnBack addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
}
@end
